//
//  MainViewController.swift
//  CBLearnDY
//
//  Created by ncimall on 2017/11/15.
//  Copyright © 2017年 ncimall. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        //  首页
        addChildVC(storyName: "Home",imgName: "btn_home_normal", selectImgName: "btn_home_selected", titleName: "首页")
        //  直播
        addChildVC(storyName: "Live",imgName: "btn_column_normal", selectImgName: "btn_column_selected", titleName: "直播")
        //  关注
        addChildVC(storyName: "Follow",imgName: "btn_live_normal", selectImgName: "btn_live_selected", titleName: "关注")
        //  我的
        addChildVC(storyName: "Profile",imgName: "btn_user_normal", selectImgName: "btn_user_selected", titleName: "我的")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

extension MainViewController {
    func addChildVC(storyName : String, imgName : String, selectImgName : String, titleName : String) {
        //  1.通过storyboard获取控制器
        let childVC = UIStoryboard.init(name: storyName, bundle: nil).instantiateInitialViewController()!
        
        childVC.tabBarItem.title = titleName
        childVC.tabBarItem.image = UIImage.init(named: imgName)
        childVC.tabBarItem.selectedImage = UIImage.init(named: selectImgName)
        //  2.将childVC作为子控制器
        addChildViewController(childVC)
    }
}
